package io.github.uicdb.gravity_generator;

import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;

import java.util.List;
import java.util.function.Predicate;

public class GGConfig {
    //BASIC
    public static ForgeConfigSpec.IntValue GG_STORAGE_SIZE;
    public static ForgeConfigSpec.IntValue GG_EXTRACT_SIZE;
    public static ForgeConfigSpec.IntValue GG_CONVERSION_RATE;
    public static ForgeConfigSpec.BooleanValue BLACK_LIST_MODE;
    public static ForgeConfigSpec.ConfigValue<List<? extends String>> BLACK_LIST;
    public static ForgeConfigSpec.ConfigValue<List<? extends String>> WHITE_LIST;
    //HARMLESS
    public static ForgeConfigSpec.IntValue HARMLESS_GG_STORAGE_SIZE;
    public static ForgeConfigSpec.IntValue HARMLESS_GG_EXTRACT_SIZE;
    public static ForgeConfigSpec.IntValue HARMLESS_GG_CONVERSION_RATE;
    public static ForgeConfigSpec.BooleanValue HARMLESS_BLACK_LIST_MODE;
    public static ForgeConfigSpec.ConfigValue<List<? extends String>> HARMLESS_BLACK_LIST;
    public static ForgeConfigSpec.ConfigValue<List<? extends String>> HARMLESS_WHITE_LIST;
    private static final Predicate<Object> ENTITY_TYPE_PREDICATE= o -> {
        String s=String.valueOf(o);
        if(!ResourceLocation.isValidResourceLocation(s))return false;
        ResourceLocation resourceLocation=new ResourceLocation(s);
        return Registry.ENTITY_TYPE.containsKey(resourceLocation);
    };
    public static void registerConfig(){
        ForgeConfigSpec.Builder serverBuilder = new ForgeConfigSpec.Builder();
        serverBuilder.comment("Basic gravity generator setting").push("Basic Generator");
        GG_STORAGE_SIZE=serverBuilder.comment("Maximum storage capacity of gravity generator.").translation("config.gg_storage_size").defineInRange("GGStorageSize", 10000,1,Integer.MAX_VALUE);
        GG_EXTRACT_SIZE=serverBuilder.comment("Maximum output of gravity generator.（per ticks)").translation("config.extract_size").defineInRange("GGExtractSize", 1000,1,Integer.MAX_VALUE);
        GG_CONVERSION_RATE=serverBuilder.comment("Conversion rate of gravity generator (distance * conversion rate = power generation)").translation("config.gg_conversion_rate").defineInRange("GGConversionRate", 10,1,Integer.MAX_VALUE);
        BLACK_LIST_MODE=serverBuilder.comment("Whether to use entity blacklist").define("BlackListMode",true);
        BLACK_LIST=serverBuilder.comment("Blacklist").defineList("BlackList",List.of(), ENTITY_TYPE_PREDICATE);
        WHITE_LIST=serverBuilder.comment("White list").defineList("WhiteList",List.of(),ENTITY_TYPE_PREDICATE);
        serverBuilder.pop();
        serverBuilder.comment("Harmless gravity generator setting").push("Harmless Generator");
        HARMLESS_GG_STORAGE_SIZE=serverBuilder.comment("Maximum storage capacity of gravity generator.").translation("config.gg_storage_size").defineInRange("GGStorageSize", 100000,1,Integer.MAX_VALUE);
        HARMLESS_GG_EXTRACT_SIZE=serverBuilder.comment("Maximum output of gravity generator.（per ticks)").translation("config.extract_size").defineInRange("GGExtractSize", 10000,1,Integer.MAX_VALUE);
        HARMLESS_GG_CONVERSION_RATE=serverBuilder.comment("Conversion rate of gravity generator (distance * conversion rate = power generation)").translation("config.gg_conversion_rate").defineInRange("GGConversionRate", 100,1,Integer.MAX_VALUE);
        HARMLESS_BLACK_LIST_MODE=serverBuilder.comment("Whether to use entity blacklist").define("BlackListMode",true);
        HARMLESS_BLACK_LIST=serverBuilder.comment("Blacklist").defineList("BlackList",List.of(), ENTITY_TYPE_PREDICATE);
        HARMLESS_WHITE_LIST=serverBuilder.comment("White list").defineList("WhiteList",List.of(),ENTITY_TYPE_PREDICATE);
        serverBuilder.pop();
        ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, serverBuilder.build());
    }
}
